package com.example.rabbit.two;

import com.example.rabbit.util.RabbitMqUtils;
import com.rabbitmq.client.Channel;

import java.io.IOException;
import java.util.Scanner;
import java.util.concurrent.TimeoutException;

/**
 * 队列模式
 * 1.自动应答
 **/
public class Task01 {
    public static void main(String[] args) throws IOException, TimeoutException {
        Channel channel = RabbitMqUtils.getChannel();
        Scanner scanner = new Scanner(System.in);
        String queueName = "hello";
        channel.queueDeclare(queueName, false, false, false, null);

        while (scanner.hasNext()) {
            String message = scanner.next();

            channel.basicPublish("", queueName, null, message.getBytes());
            System.out.println("发送消息" + message);
        }
    }

}
